import asyncio
import websockets


# 接收客户端消息并处理，这里只是简单把客户端发来的返回回去
async def recv_msg(websocket):
    while True:
        recv_text = await websocket.recv()
        print('接收到：', recv_text)
        response_text = f"your submit context: {recv_text}"
        await websocket.send(response_text)
# 发送消息
async def send_msg(websocket,msg):
    await websocket.send("服务器广播: %s" % msg)

# 服务器端主逻辑
async def main_logic(websocket, path):
    await recv_msg(websocket)
    # await send_msg(websocket)


start_server = websockets.serve(main_logic, '127.0.0.1', 8099)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
